import { request } from '@/utils/request';

export function fetchSchemeList(query?: Object) {
  return request({
    url: '/pm/experimentScheme/page',
    method: 'GET',
    query,
  });
}

export function fetchList(query?: Object) {
  return request({
    url: '/pm/experimentRecord/page',
    method: 'POST',
    data: query,
  });
}

export function getObj(id?: string) {
  return request({
    url: '/pm/experimentRecord/' + id,
    method: 'GET',
  });
}

export function delObj(ids?: object) {
  return request({
    url: '/pm/experimentRecord',
    method: 'DELETE',
    data: ids,
  });
}

export function addObj(obj?: Object) {
  return request({
    url: '/pm/experimentRecord',
    method: 'POST',
    data: obj,
  });
}

export function putObj(obj?: Object) {
  return request({
    url: '/pm/experimentRecord',
    method: 'PUT',
    data: obj,
  });
}

/**
 * 发起审批
 * @param obj
 * @returns
 */
export function submitProcess(obj?: Object) {
  return request({
    url: '/pm/experimentRecord/apply/new',
    method: 'POST',
    data: obj,
  });
}

/**
 * 撤回
 * @param obj
 * @returns
 */
export function revokeProcess(obj?: any) {
  return request({
    url: `/pm/experimentRecord/apply/cancel?comment=${obj.comment}`,
    method: 'POST',
    data: obj,
  });
}

/**
 * 设置单据状态
 * @param obj
 * @returns
 */
export function setStatusService(obj?: Object) {
  console.log(obj);
  return request({
    url: '/pm/experimentRecord/change',
    method: 'PUT',
    data: obj,
  });
}

/**
 * 同意
 * @param obj
 * @param id
 * @returns
 */
export function complete(obj?: any) {
  return request({
    url: `/pm/experimentRecord/apply/complete?pass=${obj.pass}&comment=${obj.comment}`,
    method: 'POST',
    data: { id: obj.id },
  });
}

/**
 * 驳回
 * @param obj
 * @returns
 */
export function reject(obj?: Object) {
  return request({
    url: '/pm/experimentRecord/reject',
    method: 'POST',
    data: obj,
  });
}

/**
 * 撤回
 * @param obj
 * @returns
 */
export function abandon(obj?: any) {
  return request({
    url: `/pm/experimentRecord/apply/abandon?comment=${obj.comment}`,
    method: 'POST',
    data: obj,
  });
}

/**
 * 关闭
 * @param id
 * @returns
 */
export function close(id: string) {
  return request({
    url: `/pm/experimentRecord/close/${id}`,
    method: 'POST',
  });
}

/**
 * 打开
 * @param id
 * @returns
 */
export function open(id: string) {
  return request({
    url: `/pm/experimentRecord/open/${id}`,
    method: 'POST',
  });
}

/**
 * 根据实验记录查询报检单以及检验报告信息
 * @param id
 * @returns
 */
export const getPageByTask = (params?: Object) => {
  return request({
    url: '/pm/qcMiddleCheck/pageByTask',
    method: 'GET',
    data: params,
  });
};

export function queryProcessList(obj?: Object) {
  return request({
    url: '/pm/baseProcess/getProcessParamInfo',
    method: 'GET',
    data: obj,
  });
}


export const resultByRecords = (query?: Object) => {
  return request({
    url: `/pm/qcMiddleCheck/resultByRecords`,
    method: 'GET',
    query,
  });
};
